<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>供应商设置</title>
 	<link href="../resources/css/ligerui-all.css" rel="stylesheet" type="text/css" /> 
 	<link href="../resources/css/ligerui-icons.css" rel="stylesheet" type="text/css" /> 
	<script src="../resources/js/jquery-1.9.1.min.js" type="text/javascript"></script>
	<script src="../resources/js/ligerui.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../resources/js/jquery.validate.min.js"></script>
	<script type="text/javascript" src="../resources/js/jquery.metadata.js"></script>
	<script type="text/javascript" src="../resources/js/messages_cn.js"></script>
	<script type="text/javascript" src="../resources/js/form-validate.js"></script>
    <script type="text/javascript">
    	$(function ()
        {
	              window['g'] = $("#isr").ligerGrid({
	                	checkbox: true,
	                    columns: [
	                    { display: '单位编号', name: 'supplierNO', width: 100, isSort: false},
	                    { display: '单位全称', name: 'supplierName', width: 100, isSort: false},
	    				{ display: '联系人', name: 'supplierUser', width: 100, isSort: false},
	    				{ display: '联系电话', name: 'supplierMobile', width: 100, isSort: false },
	    				{ display: '联系地址', name: 'supplierAddress', width: 250, isSort: false},
	    				{ display: '备注', name: 'memo', width: 250, isSort: false }
	                    ], //width: 1000,
	                    url : "list",
	                    width: '99.9%',
	                    pageSizeOptions: [3, 5, 7, 10],
	                    rownumbers:true
	                 });

	               
	              $.metadata.setType("attr", "validate");
		          
		          $("#form1").validate({
		         	 errorPlacement: errorPlacement,
		         	 success: mess
		          });

	              $("form").ligerForm();

	                $("#toolBar").ligerToolBar( {
	                    items : [
									{ text: '增加', click: add,icon:'add' },
									{line: true},
									{ text: '修改', click: update,icon:'edit' },
									{line: true},
									{ text: '删除', click: del, icon: 'busy' },
									{line: true},
									{ text: '导入', click: null, icon: 'back' },
									{line: true},
									{ text: '导出', click: null, icon: 'up' },
									{line: true},
									{ text: '模板下载', click: null, icon: 'attibutes' },
								]
						
	                });


	          
	                
			$("#Button1").click(function() {
				var param = $("#form0").serialize(); 
				var url = "list?" + param;
				$.post(url, 
						{'page':1, 'pagesize': 10}
				  , function(data){
						g.loadData(data);
						g.setOptions({'url': url, 'pageSizeOptions': [3, 5, 7, 10], 'page':1, 'pagesize': 10} );
					 });
				});
        });

        
        var add = function() {
        	 $("#form1").prop("action", "add");
        	$.ligerDialog.open({ target: $("#frm"), width: 650, title: '增加供应商信息' });
         };

        var update = function() {
        	 var s = g.getSelectedRows();
        	 if(s.length > 1) {
        		 $.ligerDialog.warn('修改信息不允许多选!');
             }else if(s.length == 0) {
            	 $.ligerDialog.warn('请选择一条记录!');
             }else{
                 $("#supplierNO").val(s[0].supplierNO);
                 $("#supplierName").val(s[0].supplierName);
                 $("#supplierUser").val(s[0].supplierUser);
                 $("#supplierMobile").val(s[0].supplierMobile);
                 $("#supplierAddress").val(s[0].supplierAddress);
                 $("#memo").val(s[0].memo);
                 $("#form1").prop("action", "update");
                 $("<input type='hidden' name='supplierID' id='supplierID' value=" + s[0].supplierID + ">").appendTo($("#form1"));
        		$.ligerDialog.open({ target: $("#frm"), width: 650, title: '修改供应商信息' });
             };

           };

        var del = function() {
        	var s = g.getSelectedRows();
        	if(s.length!=0) {
        	$.ligerDialog.confirm('您真的要删除所选择的信息吗?', function (yes) { 
	              if(yes) {
	        	   var p = new Array();
	        	   for(var i=0; i<s.length; i++) {
	            	   p.push(s[i].supplierID);
	               }
	        	   var arrs = JSON.stringify(p);
	        		$.get("/baohua/supplier/del/" + arrs, function(data){
	            		var mess = eval(data);
	            		  switch (mess)
	                      {
	                          case "success":
	                        	  g.loadData(); 
	                              $.ligerDialog.success('删除成功！');
	                              break;
	                          case "systemerror":
	                              $.ligerDialog.warn('系统出现错误！');
	                              break;
	                          case "error":
	                              $.ligerDialog.error('供应商不存在, 不能删除！');
	                              break;
	                      }
	            	}); 
	            	}
        	});
        	}else {
        		$.ligerDialog.warn('请选择一条记录!');
             }
           };
    </script>
    <style type="text/css">
		#isr #toolBar { margin-left:5px;}
        .l-table-edit-td{ padding:3px;}
        .l-button-submit,.l-button-reset{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
        .l-verify-tip{ left:230px; top:120px;}
</style>
</head>

<body>
 <!-- 1.导航条 -->
   <span style=" margin: 5px 10px; display: block; font-weight: bold;">宝华茶餐厅 > 基础信息管理 > 供应商设置</span>
 <!-- 2.查询条件 --> 
   <div id="isearch" style="width:100%; margin-bottom: 5px;">
	  <form name="form0" method="post"  id="form0">
        <table cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td align="right" class="l-table-edit-td" width="11%">供应商编号:</td>
                <td align="left" class="l-table-edit-td" style="width:23px">
                   <input name="supplierNO" type="text" ltype="text" id="i_supplierNO"/>
                </td>
                
                <td align="right" class="l-table-edit-td" width="10%">单位名称:</td>
                <td align="left" class="l-table-edit-td" style="width:23px"><input name="supplierName" type="text" ltype="text" id="i_supplierName"/></td>
            </tr>
             <tr>
                 <td colspan="3">&nbsp;</td>
                 <td>
	                 <input type="button" value="查询" id="Button1" class="l-button l-button-submit" /> 
		             <input type="reset" value="重置" class="l-button l-button-reset"/>
		         </td>
            </tr>
        </table>
    </form>
    </div>
 <!-- 3.g工具条 -->  
    <div id="toolBar"></div>
 <!-- 4.供应商列表 -->   
	<div id="isr"></div>
 <!-- 5.供应商增加信息(弹框) -->	
	<div id="frm" style="width:600px; margin:3px; display:none;">
     	<form name="form1" method="post"  id="form1">
        <table cellpadding="0" cellspacing="0" width="600px">
            <tr>
                <td align="right" class="l-table-edit-td" width="100px">单位编号:</td>
                <td align="left" class="l-table-edit-td" style="width:160px"><input name="supplierNO" type="text" ltype="text" id="supplierNO" validate="{required:true,minlength:3,maxlength:10}"/></td>
                <td align="left" width="40px"></td>
                
                <td align="right" class="l-table-edit-td" width="100">单位名称:</td>
                <td align="left" class="l-table-edit-td" style="width:160px"><input name="supplierName" type="text" ltype="text"  id="supplierName" validate="{required:true,minlength:3,maxlength:10}"/></td>
                <td align="left" width="40px"></td>
            </tr>
             
            <tr>
                <td align="right" class="l-table-edit-td" width="100px">联系人:</td>
                <td align="left" class="l-table-edit-td" style="width:160px"><input name="supplierUser" id="supplierUser" type="text" ltype="text"/></td>
                <td align="left" width="40px"></td>
                
                <td align="right" class="l-table-edit-td" width="100px">手机号码:</td>
                <td align="left" class="l-table-edit-td" style="width:160px"><input name="supplierMobile" type="text" id="supplierMobile" ltype="text" validate="{istelephone:true}"></td>
                <td align="left" width="40px"></td>
            </tr>
            
              <tr>
                <td align="right" class="l-table-edit-td" width="100px">住址:</td>
                <td align="left" class="l-table-edit-td"  colspan="4" width="460px">
                	<textarea cols="20" rows="1" class="l-textarea" style="width:460px" name="supplierAddress" id="supplierAddress"></textarea>
                </td>
                <td align="left" width="40px"></td>
            </tr> 
                 
            <tr>
                <td align="right" class="l-table-edit-td" width="100px">备注:</td>
                <td align="left" class="l-table-edit-td" colspan="4"> 
                <textarea cols="100" rows="4" class="l-textarea" style="width:460px" name="memo" id="memo"></textarea>
                </td>
                <td align="left" width="40px"></td>
            </tr>
            
            <tr>
               <td colspan="4">&nbsp;</td>
               <td align="right">
                  <input type="submit" value="提交" id="Button1" class="l-button l-button-submit" /> 
				  <input type="reset" value="重置" class="l-button l-button-reset"/>
               </td>
                <td align="left" width="40px"></td>
            </tr>
        </table>
 	<br />
    </form>
    </div>
 
</body>

</html>